<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改</title>

    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <link th:href="@{/css/role/role.css}" rel="stylesheet"/>

    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/layer/layer.min.js}"></script>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <!--/*@thymesVar id="role" type="com.lzw.yin.domain.entity.Role"*/-->
    <form class="form-horizontal m" id="form-role-edit" th:object="${role}">
        <input id="roleId" name="roleId" type="hidden" th:field="*{roleId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">角色名称：</label>
            <div class="col-sm-8">
                <label for="roleName" style="display: inline"></label><input class="form-control" type="text"
                                                                             name="roleName" id="roleName"
                                                                             th:field="*{roleName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">权限字符：</label>
            <div class="col-sm-8">
                <label for="roleKey" style="display: inline"></label><input class="form-control" type="text"
                                                                            name="roleKey" id="roleKey"
                                                                            th:field="*{roleKey}" required>
                <span class="help-block m-b-none"><i
                        class="fa fa-info-circle"></i> 控制器中定义的权限字符，如：@RequiresRoles("")</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">显示顺序：</label>
            <div class="col-sm-8">
                <label for="roleSort" style="display: inline"></label><input class="form-control" type="text"
                                                                             name="roleSort" id="roleSort"
                                                                             th:field="*{roleSort}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="status" th:checked="${role.status == '0' ? true : false}">
                    <span></span>
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <label for="remark" style="display: inline"></label><input id="remark" name="remark"
                                                                           class="form-control" type="text"
                                                                           th:field="*{remark}">
            </div>
        </div>

    </form>
</div>

<script>

    function edit() {
        let roleId = $("input[name='roleId']").val();
        let roleName = $("input[name='roleName']").val();
        let roleKey = $("input[name='roleKey']").val();
        let roleSort = $("input[name='roleSort']").val();
        let status = $("input[id='status']").is(':checked') === true ? 0 : 1;
        let remark = $("input[name='remark']").val();

        $.ajax({
            cache: true,
            type: "POST",
            url: "/role/edit",
            data: {
                "roleId": roleId,
                "roleName": roleName,
                "roleKey": roleKey,
                "roleSort": roleSort,
                "status": status,
                "remark": remark
            },
            async: false,
            error: function () {
                layer.alert("系统错误", {
                    icon: "2",
                    title: "系统提示",
                    btn: ['确认'],
                    btnclass: ['btn btn-primary'],
                });
            }, success: function (result) {
                if (result.code !== 0) {
                    layer.alert(result.msg, {
                        title: "系统提示",
                        btn: ['确认'],
                        btnclass: ['btn btn-primary'],
                    });
                }
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        });
    }


</script>
</body>
</html>
